package aaa.question.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import aaa.common.annotation.Log;
import aaa.common.core.controller.BaseController;
import aaa.common.core.domain.AjaxResult;
import aaa.common.enums.BusinessType;
import aaa.question.domain.QuesQuestionBank;
import aaa.question.service.IQuesQuestionBankService;
import aaa.common.utils.poi.ExcelUtil;
import aaa.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 题目库Controller
 * 
 * @author xyy
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/question/question")
public class QuesQuestionBankController extends BaseController
{
    @Autowired
    private IQuesQuestionBankService quesQuestionBankService;

    /**
     * 查询题目库列表
     */
    @PreAuthorize("@ss.hasPermi('question:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuesQuestionBank quesQuestionBank)
    {
        startPage();
        List<QuesQuestionBank> list = quesQuestionBankService.selectQuesQuestionBankList(quesQuestionBank);
        return getDataTable(list);
    }

    /**
     * 导出题目库列表
     */
    @PreAuthorize("@ss.hasPermi('question:question:export')")
    @Log(title = "题目库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuesQuestionBank quesQuestionBank)
    {
        List<QuesQuestionBank> list = quesQuestionBankService.selectQuesQuestionBankList(quesQuestionBank);
        ExcelUtil<QuesQuestionBank> util = new ExcelUtil<QuesQuestionBank>(QuesQuestionBank.class);
        util.exportExcel(response, list, "题目库数据");
    }


    /**
     * 获取题目库详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:question:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return success(quesQuestionBankService.selectQuesQuestionBankByQuestionId(questionId));
    }


    @PreAuthorize("@ss.hasPermi('question:question:list')")
    @PostMapping(value = "/import")

    public AjaxResult importdate(MultipartFile file) throws IOException {
        return success(quesQuestionBankService.importdate(file));
    }

    /**
     * 新增题目库
     */
    @PreAuthorize("@ss.hasPermi('question:question:add')")
    @Log(title = "题目库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuesQuestionBank quesQuestionBank)
    {
        return toAjax(quesQuestionBankService.insertQuesQuestionBank(quesQuestionBank));
    }

    /**
     * 修改题目库
     */
    @PreAuthorize("@ss.hasPermi('question:question:edit')")
    @Log(title = "题目库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuesQuestionBank quesQuestionBank)
    {
        return toAjax(quesQuestionBankService.updateQuesQuestionBank(quesQuestionBank));
    }

    /**
     * 删除题目库
     */
    @PreAuthorize("@ss.hasPermi('question:question:remove')")
    @Log(title = "题目库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(quesQuestionBankService.deleteQuesQuestionBankByQuestionIds(questionIds));
    }
}
